/**
 * Redirects from the short URL to the real URL.
 */
Hyperlink.prototype.main_action = function() {
    this.clicks++; // increase the click counter

    res.redirect(this.url);
    return;
}

/**
 * Render a short preview of the shortened URL
 */
Hyperlink.prototype.preview_action = function() {
    // render the Hypertext's preview.skin;
    // the output will be stored in res.body, which will be
    // displayed in the global main.skin by <% respone.body %>
    res.data.body = this.renderSkinAsString("preview");
   
    renderSkin("main"); // renders the global main.skin
    return;
}

/**
 * Renders the form to confirm the deletion. If the request is
 * a POST, the link will be removed from the Root collection and
 * from the database.
 */
Hyperlink.prototype.delete_action = function() {
    // Real apps now should check the input or
    // if there is a logged in user.
    if (req.isPost()) {
        root.removeChild(this);
        this.remove();
        res.redirect(root.href("overview"));
    }
    
    res.data.body = this.renderSkinAsString("delete");
    renderSkin("main");
    return;
}